<template>
	<view class="mine_wrapper" v-if="mineInfo.user">
		<view class="ore_wrap" @click="jumpFrozenAssets">
			<image src="https://pcdcoin.oss-cn-chengdu.aliyuncs.com/pcdApp/mine/kuangshi.png"></image>
		</view>
		<view class="mine_info--list">
			<view class="mine_info--income">
				<view class="income_item">
					<text>累计总收益(PCD)</text>
					<text>{{$util.roundNumber(mineInfo.user.total_profit,2)}}</text>
				</view>
				<view class="income_item">
					<text>昨日总收益(PCD)</text>
					<text>{{$util.roundNumber(mineInfo.user.yesterday_profit,2)}}</text>
				</view>
			</view>
			<view class="mine_info--header">
				<view class="header_top">
					<text>{{mineInfo.user.profit_name}}矿场</text>
					<text @click="onMinerUpgrade">升级</text>
				</view>
				<view class="header_bottom">团队收益率：{{mineInfo.user.profit_value}}</view>
			</view>
		</view>
		<view class="mine_income">
			<view class="mine__item_income" @click="jumpMineProfit">
				<view class="item_node">
					<text>挖矿收益</text>
					<image src="https://pcdcoin.oss-cn-chengdu.aliyuncs.com/pcdApp/common/arrowRight.svg"></image>
				</view>
				<view class="item_node income_sum">
					<text>累计(PCD)</text>
					<text>{{$util.roundNumber(mineInfo.mine.profit,2)}}</text>
					<image src="https://pcdcoin.oss-cn-chengdu.aliyuncs.com/pcdApp/mine/blueStart.png"></image>
				</view>
				<view class="item_node">
					<text>昨日(PCD)</text>
					<text>{{$util.roundNumber(mineInfo.mine.yesterday_profit,2)}}</text>
				</view>
			</view>
			<view class="mine__item_income" @click="jumpRecruitProfit">
				<view class="item_node">
					<text>招募收益</text>
					<image src="https://pcdcoin.oss-cn-chengdu.aliyuncs.com/pcdApp/common/arrowRight.svg"></image>
				</view>
				<view class="item_node income_sum">
					<text>累计(PCD)</text>
					<text>{{$util.roundNumber(mineInfo.invite.profit,2)}}</text>
					<image src="https://pcdcoin.oss-cn-chengdu.aliyuncs.com/pcdApp/mine/blueStart.png"></image>
				</view>
				<view class="item_node">
					<text>昨日(PCD)</text>
					<text>{{$util.roundNumber(mineInfo.invite.yesterday_profit,2)}}</text>
				</view>
			</view>
		</view>
		
		<!-- 版本更新对话框 -->
		<wx-dialog :showDialog="showChangeNameDialog" direction="center">
			<template v-slot:dialogContent>
				<view class="dialog_wrap">
					<view class="dialog_title">温馨提示</view>
					<view class="dialog_content">
						有新版本了，请更新！
					</view>
					<view class="tips_wrap">
						<checkbox-group @change="radioChange" class="check_box">
							<checkbox value="true" />
							<text>不再提示</text>
						</checkbox-group>
					</view>
					<view class="handle_wrap">
						<button type="warn" class="dialog_btn" @click="onUpdateDialog('confirm')">查看</button>
						<button class="dialog_btn cancel_btn" @click="onUpdateDialog('cancel')">取消</button>
					</view>
				</view>
			</template>
		</wx-dialog>
	</view>
</template>

<script>
	import wxDialog from "@/components/wx-dialog/wx-dialog.vue"
	export default {
		data() {
			return {
				mineInfo: {}, // 矿池信息
				showChangeNameDialog:false, //修改名字对话框状态
				userInfo:{}
			}
		},
		onLoad() {
			this.getMineInfo()
			this.getUserInfo()
			// #ifdef  APP-PLUS
			this.onUpdate()
			// #endif
		},
		onShow(){
			this.getMineInfo()
		},
		onPullDownRefresh() {
			this.getMineInfo()
		},
		methods: {
			// 获取矿场信息
			getMineInfo() {
				this.$api.getMineInfo({}, res => {
					if (res.data.type === "ok") {
						this.mineInfo = res.data.message
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
					uni.stopPullDownRefresh()
				})
			},
			jumpMineProfit() {
				uni.navigateTo({
					url: '/pages/mine/mineProfit'
				})
			},
			jumpRecruitProfit() {
				uni.navigateTo({
					url: '/pages/mine/recruitProfit'
				})
			},
			onMinerUpgrade(){
				uni.navigateTo({
					url: '/pages/mine/mineUpgrade'
				})
			},
			// 更新
			onUpdate(){
				// 获取当前版本号
				let req = {
					appid: plus.runtime.appid,
					version: plus.runtime.version
				};
				// 判断是否更新
				this.$api.getUpdate({}, res => {
					if (res.data.type == 'ok') {
						// 获取新的版本号
						let newVersion = res.data.message.app_version;
						if(uni.getStorageSync('app_version')){
							// 本地缓存的版本
							let storageVersion = uni.getStorageSync('app_version').app_version;
							if(newVersion != storageVersion){
								uni.setStorageSync('is_update_prompt',true)
							}
						}
						uni.setStorageSync('app_version', res.data.message);	
						console.log(res.data.message)			
						// 如果版本有差异，则继续判断
						if (newVersion != req.version) {
							const isUpdate = uni.getStorageSync('is_update_prompt')
							if(isUpdate===false){
								return
							}else{
								this.showChangeNameDialog = true
							}
						}
					}
				})
			},
			// 更新对话框
			onUpdateDialog(arg){
				if(arg === 'confirm'){
					uni.navigateTo({
						url: '/pages/update/index'
					})
				}
				this.showChangeNameDialog = false
			},
			// 不再提示框
			radioChange(val) {
				// 有值说明被选中
				if (val.detail.value.length) {
					uni.setStorageSync('is_update_prompt', false);
				} else {
					uni.setStorageSync('is_update_prompt', true);
				}
			},
			// 获取用户信息
			getUserInfo() {
				this.$api.getUserInfo({}, (res) => {
					if (res.data.type == 'ok') {
						this.userInfo = res.data.message.baseInfo;
						uni.setStorageSync('user_info', res.data.message); //存储用户信息
					}
				})
			},
			// 跳转冻结页面
			jumpFrozenAssets(){
				uni.navigateTo({
					url: '/pages/wallet/frozenAssets'
				})
			}
		},
		components: {
			wxDialog
		}
	}
</script>

<style lang="scss" scoped>
	.mine_wrapper {
		height: 100vh;
		background-image: url('https://pcdcoin.oss-cn-chengdu.aliyuncs.com/pcdApp/mine/minebg.png');
		background-size: cover;
		background-position: 50% 0%;
		overflow: hidden;
	}
	
	.ore_wrap{
		position:fixed;
		left: 45%;
		@keyframes oremove {
			0%{
				top:23%;
			}
			50%{
				top:21%;
			}
			100%{
				top:23%;
			}
		}
		animation:oremove 3s infinite;
		image{
			width: 78upx;
			height:191upx;
		}
	}
	
	.mine_info--list {
		height:300upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #FFFFFF;
		.mine_info--income {
			margin-top:50upx;
			margin-left:26upx;
			.income_item{
				text{
					display: block;
				}
			}
			.income_item:last-child{
				margin-top:34upx;
			}
		}

		.mine_info--header {
			display: flex;
			flex-direction: column;
			margin-top:50upx;
			.header_top{
				height: 80upx;
				display: flex;
				align-items: center;
				border-top-left-radius: 80upx;
				border-bottom-left-radius: 80upx;
				background-color: #575A6A;
				text:first-child{
					margin:0 20upx 0 28upx;
					font-size: 16px;
				}
				text:last-child{
					margin-right:10upx;
					padding:5upx 25upx;
					background-color: #176CE2;
					border-radius: 40upx;
				}
			}
			.header_bottom{
				margin-top:20upx;
				text-align: center;
				font-size: 12px;
			}
		}
	}

	.mine_income {
		width: 100%;
		position: fixed;
		bottom: 50upx;
		left: 0;
		display: flex;
		justify-content: space-around;
		.mine__item_income {
			width: 45%;
			display: flex;
			flex-direction: column;
			padding:0 36upx;
			box-sizing: border-box;
			border-radius:10px;
			background-color: rgba(255,255,255,.91);

			.item_node {
				width:100%;
				padding:20upx 0;
				text{
					display: block;
				}
				text:first-child {
					color: #666666;
				}

				text:last-child {
					color: #333333;
				}
			}

			.item_node:nth-child(1) {
				display: flex;
				justify-content: space-between;
				align-items: center;
				text{
					font-weight: 700;
					font-size: 15px;
				}
				image{
					width:20upx;
					height: 20upx;
				}
			}
			.income_sum {
				position: relative;
				image{
					width:42upx;
					height: 32upx;
					position: absolute;
					top:0;
					right:0;
				}
			}
			.income_sum:after{
					content:"";
					position:absolute;
					bottom:0;
					left:0;
					right:0;
					border-top:1px solid rgba(0,0,0,0.1);
					-webkit-transform:scaleY(.5);
					-webkit-transform-origin:0 0;
			}
		}
	}
	
	.dialog_wrap {
		width:80%;
		background-color:#FFFFFF;
		margin:0 auto;
		border-radius: 10upx;
		overflow: hidden;
		.dialog_title {
			position: relative;
			height: 100upx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 15px;
		}
		.dialog_title:after{
		    content:"";
			position:absolute;
		    bottom:0;
		    left:0;
		    right:0;
		    border-top:1px solid rgba(0,0,0,0.1);
		    -webkit-transform:scaleY(.5);
		    -webkit-transform-origin:0 0;
		}
	
		.dialog_content {
			padding: 0 40upx;
			margin: 40upx 0;
	
			input {
				height: 50upx;
				padding: 0 10upx;
				border-bottom: 1px solid #E0DFDF;
				text-align: center;
			}
	
		}
	
		.tips_wrap {
			padding: 0 40upx;
			.check_box {
				transform: scale(0.7);
				margin-left: -17%;
				text {
					font-size: 15px;
				}
			}
		}
		
		.handle_wrap{
				display: flex;
				justify-content: space-between;
				margin:42upx 0 37upx 0;
				.dialog_btn{
					width:43%;
					height: 70upx;
					line-height: 70upx;	
					border-radius: 70upx;
					background-color: #E03E4D;
					font-size: 14px;
				}
				.cancel_btn{
					border:1px solid #E03E4D;
					background-color: #FFFFFF;
					color:#E03E4D;
				}
			}
	}
</style>